<!DOCTYPE html>
<html lang="zxx">

<head>
	<title>信标管理</title>
	<!-- custom-theme -->
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="keywords" content="" />
	<script type="application/x-javascript">
			addEventListener("load", function() {
				//将0改为2000 hpt update 20200903
				setTimeout(hideURLbar, 2000);
			}, false);
			function hideURLbar() {
				window.scrollTo(0, 1);
			}
		</script>
	<!-- //custom-theme -->
	<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
	<link rel="stylesheet" type="text/css" href="css/table-style.css" />
	<!-- <link rel="stylesheet" type="text/css" href="css/basictable.css" /> -->
	<link href="css/component.css" rel="stylesheet" type="text/css" media="all" />
	<!-- <link href="css/style_grid.css" rel="stylesheet" type="text/css" media="all" /> -->
	<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
	<link href="css/bootstrap-table.css" rel="stylesheet" type="text/css" media="all" />
	<!-- font-awesome-icons -->
	<link href="css/font-awesome.css" rel="stylesheet">
	<!-- //font-awesome-icons -->
	<link href="http://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i,800"
		rel="stylesheet">
	<style>
		input::-webkit-input-placeholder {
			/* placeholder颜色  */
			color: #f2f4f6;
			/* placeholder字体大小  */
			font-size: 12px;
		}
	</style>


</head>
<script src="Plugins/vue.js"></script>
<script>
	window.onload = function () {
		var userRole = JSON.parse(localStorage.getItem("loginUrseData")).role;
		var vm = new Vue({
			el: "#gn-menun",
			data: {
				role: userRole
			}
		})
	}
</script>

<body>
	<!-- banner -->
	<div class="wthree_agile_admin_info">
		<!-- /w3_agileits_top_nav-->
		<!-- /nav-->
		<div class="w3_agileits_top_nav">
			<ul id="gn-menu" class="gn-menu-main">
				<!-- /nav_agile_w3l -->
				<li class="gn-trigger">
					<a class="gn-icon gn-icon-menu"><i class="fa fa-bars" aria-hidden="true"></i><span>Menu</span></a>
					<nav class="gn-menu-wrapper">
						<div class="gn-scroller scrollbar1">
							<ul class="gn-menu agile_menu_drop" id="gn-menun">
								<!-- <li>
										<a href="main-page.html"> <i class="fa fa-tachometer"></i> Dashboard</a>
									</li> -->
								<template v-bind: v-if="role === 1 || role === 2">
									<li>
										<a href="ACommunity.html"> <i class="fa fa-table"
												aria-hidden="true"></i>小区管理</a>
									</li>
								</template>
								<template v-bind: v-if="role === 1 || role === 2">
									<li>
										<a href="#"><i class="fa fa-cogs" aria-hidden="true"></i> 设备管理 <i
												class="fa fa-angle-down" aria-hidden="true"></i></a>
										<ul class="gn-submenu">
											<li class="mini_list_agile"><a href="ABarcode.html"><i
														class="fa fa-caret-right" aria-hidden="true"></i>
													二维码管理</a></li>
											<li class="mini_list_w3">
												<a href="ABeacon.html"> <i class="fa fa-caret-right"
														aria-hidden="true"></i> 信标管理</a>
											</li>
											<li class="mini_list_w3">
												<a href="ALift.html"> <i class="fa fa-caret-right"
														aria-hidden="true"></i> DTU管理</a>
											</li>
											<li class="mini_list_w3">
												<a href="generate_code.html"> <i class="fa fa-caret-right"
														aria-hidden="true"></i>二维码生成</a>
											</li>
										</ul>
									</li>
								</template>
								<template v-bind: v-if="role === 1 || role === 3 || role === 4">
									<li>
										<a href="#"> <i class="fa fa-file-text-o" aria-hidden="true"></i>申请权限管理 <i
												class="fa fa-angle-down" aria-hidden="true"></i></a>
										<ul class="gn-submenu">
											<li class="mini_list_agile"><a href="approve.html"><i
														class="fa fa-caret-right" aria-hidden="true"></i>已通过申请权限管理</a>
											</li>
											<li class="mini_list_w3"><a href="refuse.html"><i class="fa fa-caret-right"
														aria-hidden="true"></i>已拒绝申请权限管理</a></li>
											<li class="mini_list_w3"><a href="table.html"><i class="fa fa-caret-right"
														aria-hidden="true"></i>权限申请管理</a></li>
										</ul>
									</li>
								</template>
								<template v-bind: v-if="role === 1 || role === 3">
									<li>
										<a href="AUser.html"> <i class="fa fa-table" aria-hidden="true"></i>用户管理</a>
									</li>
								</template>
							</ul>
						</div>
						<!-- /gn-scroller -->
					</nav>
				</li>
				<!-- //nav_agile_w3l -->
				<li class="second logo">
					<h1><a href="manage.html"><i class="fa fa-graduation-cap" aria-hidden="true"></i>1智能呼梯管理平台</a>
					</h1>
				</li>
				<li class="second admin-pic">
					<ul class="top_dp_agile">
						<li class="dropdown profile_details_drop">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
								<div class="profile_img">
									<span class="prfil-img"><img src="images/admin.jpg" alt=""> </span>
								</div>
							</a>
							<ul class="dropdown-menu drp-mnu">
								<li> <a href="login.html"><i class="fa fa-sign-out"></i> 登出</a> </li>
							</ul>
						</li>

					</ul>
				</li>
				<li class="second top_bell_nav">
					<ul class="top_dp_agile ">
						<li class="dropdown head-dpdn" id="tongzhiCount">
							<a href="table.html"  id="tongzhiId" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true"><i
									class="fa fa-bell-o" aria-hidden="true"></i>
								<span class="badge blue" id="unreadCount"></span></a>
							<ul class="dropdown-menu">
								<li>
									<div class="notification_header">
										<h3>你的通知</h3>
									</div>
								</li>
								<li>
									<a href="table.html">
										<div class="notification_desc">
											<h6>你有<span style="color: red;" id="unreadCount"></span>个申请待处理</h6>
										</div>
										<div class="clearfix"></div>
									</a>
								</li>
								<div class="notification_bottom">
									<a href="table.html">查看详情</a>
								</div>
						</li>
					</ul>
				</li>

			</ul>
			</li>
			<li class="second top_bell_nav">
				<ul class="top_dp_agile ">
					<li class="dropdown head-dpdn">
						<ul class="dropdown-menu">
						</ul>
					</li>

				</ul>
			</li>
			<li></li>
			</ul>
			<!-- //nav -->

		</div>
		<div class="clearfix"></div>
		<!-- //w3_agileits_top_nav-->

		<!-- /inner_content-->
		<div class="inner_content">
			<!-- /inner_content_w3_agile_info-->

			<!-- breadcrumbs -->
			<div class="w3l_agileits_breadcrumbs">
				<div class="w3l_agileits_breadcrumbs_inner">
					<ul>
						<li>首页<span>«</span></li>
						<li>设备管理<span>«</span></li>
						<li>二维码管理</li>
					</ul>
				</div>
			</div>
			<!-- //breadcrumbs -->

			<div class="inner_content_w3_agile_info two_in">
				<h2 class="w3_inner_tittle">二维码列表</h2>
				<div class="panel-body">
					<div class="panel panel-default">
						<div class="panel-heading">查询条件</div>
						<div class="panel-body">
							<form id="formSearch" class="form-horizontal">
								<div class="form-group" style="margin-top: 15px">
									<!-- <label class="control-label col-sm-1" for="txt_search_departmentname">二维码编号</label> -->
									<div class="col-sm-3">
										<input type="text" class="form-control" id="txt_search_departmentname"
											placeholder="请输入二维码编号\电梯编号\电梯地址">
									</div>
									<div class="col-sm-4" style="text-align: left;">
										<button type="button" style="margin-left: 50px" id="btn_query"
											class="btn btn-primary" onclick="search()">查询</button>
									</div>
								</div>
							</form>
						</div>
					</div>
					<div id="toolbar">
						<button class="btn" id="passAll"
							onclick="javascript:window.location.href='ABarcodeAdd.html'">新增</button>
						<button class="btn" id="refuseAll" onclick="refuseAll()">删除</button>
					</div>
					<table id="tb_application"></table>
					<!-- //tables -->
				</div>
				<!-- //inner_content_w3_agile_info-->
			</div>
			<!-- //inner_content-->
			<!--copy rights start here-->
			<div class="copyrights">
				<p>Copyright &copy; 2020.<a href="https://www.yungtay.com.cn/" target="_blank">1电梯设备(中国)有限公司
						沪ICP备16033938号</a></p>
			</div>
			<!--copy rights end here-->
			<!-- js -->
			<!-- 隐藏input为了保存拒绝的理由 -->
			<input type="hidden" name="" id="reason" value="" />
			<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
			<script src="js/modernizr.custom.js"></script>

			<script src="js/classie.js"></script>
			<script src="js/gnmenu.js"></script>
			<script>
				new gnMenu(document.getElementById('gn-menu'));
			</script>
			<!-- tables -->

			<script type="text/javascript">
				function formatDate(nowDate) {
					var year = nowDate.getFullYear();
					var month = nowDate.getMonth() + 1;
					month = month > 9 ? month : "0" + month;
					var date = nowDate.getDate();
					date = date > 9 ? date : "0" + date;
					var hour = nowDate.getHours();
					hour = hour > 9 ? hour : "0" + hour;
					var miunte = nowDate.getMinutes();
					miunte = miunte > 9 ? miunte : "0" + miunte;
					var second = nowDate.getSeconds();
					second = second > 9 ? second : "0" + second;
					return year + "-" + month + "-" + date + " " + hour + ":" + miunte + ":" + second;
				}
			</script>
			<!-- //js -->
			<script src="js/screenfull.js"></script>
			<script>
				$(function () {
					$('#supported').text('Supported/allowed: ' + !!screenfull.enabled);

					if (!screenfull.enabled) {
						return false;
					}

					$('#toggle').click(function () {
						screenfull.toggle($('#container')[0]);
					});
				});
			</script>
			<script src="js/jquery.nicescroll.js"></script>
			<script src="js/scripts.js"></script>

			<script type="text/javascript" src="js/bootstrap-3.1.1.min.js"></script>
			<script type="text/javascript" src="js/bootstrap-table.min.js"></script>
			<script type="text/javascript" src="js/bootstrap-table-zh-CN.js"></script>
			<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
				<div id='container' class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
									aria-hidden="true">×</span></button>
							<h4 class="modal-title" id="myModalLabel">修改二维码信息</h4>
						</div>
						<div class="modal-body">
							<div class="form-body form-body-info">
								<form>
									<div class="form-group valid-form">
										<input type="text" class="form-control at-required" id="codeId"
											placeholder="请输入二维码编号" required="true" v-model="qrCode.codeId">
									</div>
									<div class="form-group">
										<select name="field-2" id="field-2" required="true" class="form-control"
											style="padding-top: 0px;padding-bottom: 0px;" v-model="qrCode.liftId">
											<option value="" disabled selected hidden>请选择DTU</option>
											<option :value="types.liftId" v-for="types in typeList">{{types.address}}
											</option>
										</select>
									</div>
									<div class="form-group valid-form">
										<input type="text" class="form-control at-required" id="floor"
											placeholder="请输入楼层" required="true" v-model="qrCode.floor">
									</div>
									<div class="form-group">
										<input type="button" class="btn btn-primary" @click="onSubmit()" value="提交" />
										<!-- <button type="submit" class="btn btn-primary" @click="onSubmit()">提交</button> -->
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="qrcode"></div>
			<script src="src/jquery.qrcode.js"></script>
			<script src="src/qrcode.js"></script>
			<script>
				// $(".qrcode").qrcode({width:200,height:200,text:"http://www.baidu.com"});
			</script>
</body>
<script src="Plugins/layui/layui.js"></script>
<script src="Plugins/vue.js"></script>
<script src="js/common.js"></script>
<script type="text/javascript">
	var my_token = JSON.parse(localStorage.getItem("loginUrseData")).token;
	var refuseIds = [];
	$(function () {
		//首先生成待处理数量
		$.ajax({
			type: "get",
			url: 'https://ytcloud2.yungtay.com.cn:1443/proServer/api/access/getPendingCount',
			contentType: 'application/json;charset=utf-8',
			headers: {
				Token: my_token //这里是Token
			},
			data: { communityId: JSON.parse(localStorage.getItem("loginUrseData")).communityId, status: 1 },
			success: function (res) {
				$("[id=unreadCount]").text(res.data.num)
				if (res.data.num == 0) {
					$("[id=tongzhiId]").hide()
				}
			},
			error: function (error) {
				alert('登陆过期,请重新登录')
				window.location.href = "login.html";
				console.log(error);
			}
		})
		// 1.初始化Table
		var oTable = new TableInit();
		oTable.Init();

		// 2.初始化Button的点击事件
		var oButtonInit = new ButtonInit();
		oButtonInit.Init();

		$("#btn_submit").click(function () {
			var remark = $("#deblock_udid").val();
			console.log(refuseIds)
			$.ajax({
				type: "get",
				// url: 'https://ytcloud2.yungtay.com.cn:1443/proServer/access/refuseApplicatons',
				url: 'https://ytcloud2.yungtay.com.cn:1443/proServer/api/access/refuse',
				contentType: 'application/json;charset=utf-8',
				headers: {
					Token: my_token //这里是Token
				},
				data: {
					"ids": refuseIds,
					note: remark
				},
				traditional: true,
				success: function (res) {
					console.log(res)
					location.reload()
				},
				error: function (error) {
					alert('登陆过期,请重新登录')
					window.location.href = "login.html";
					console.log(error);
					alert('登陆过期,请重新登录')
					window.location.href = "login.html";
				}
			})

		})


	});

	function search() {
		$("#tb_application").bootstrapTable("refresh");
	}
	var vm = new Vue({
		el: "#container",
		data: {
			typeList: [],
			qrCode: {
				codeId: '',
				liftId: '',
				floor: '',
				id: '',
				liftAddress: ''
			}
		},
		mounted: function () {
			console.log("执行更新方法")
			setTimeout(function () {
				vm.roleList();
			});
		},
		methods: {
			//获取角色列表
			roleList: function () {
				var url = "https://ytcloud2.yungtay.com.cn:1443/proServer/api/lift/getList?address=";

				$.ajax({
					type: "GET",
					url: url,
					success: function (res) {
						console.log(res);
						if (res.code == 200) {
							vm.typeList = res.data;
						} else {
							alert('获取信息失败！');
						}
					},
					error: function () {
						alert('登陆过期,请重新登录')
						window.location.href = "login.html";
						alert('获取信息失败！');
					}
				});
			},
			onSubmit() {
				var layer = '';
				layui.use('layer', function () {
					layer = layui.layer;
				});
				if (!vm.qrCode.codeId) {
					layer.msg('请填写二维码id！');
					return
				} else if (!vm.qrCode.liftId) {
					layer.msg('请选择DTU！');
					return
				} else if (!vm.qrCode.floor) {
					layer.msg('请填写楼层！');
					return
				}
				console.log("执行了修改方法二维码")
				console.log(vm.qrCode)
				// var url = "http://10.21.30.26:9090/proServer/api/qrCode/update";
				var url = "https://ytcloud2.yungtay.com.cn:1443/proServer/api/qrCode/update";
				var result = vm.typeList.find((item) => { //model就是上面的数据源
					return item.liftId === vm.qrCode.liftId; //筛选出匹配数据
				})
				vm.qrCode.liftAddress = result.address
				vm.qrCode.liftId = result.liftId
				$.ajax({
					type: "post",
					url: url,
					contentType: 'application/json;charset=utf-8',
					headers: {
						Token: my_token //这里是Token
					},
					data: JSON.stringify(vm.qrCode),
					success: function (res) {
						if (res.code === 200) {
							window.location.href = "ABarcode.html";
							layer.msg("修改成功");
						} else {
							layer.msg(res.message);
						}
					},
					error: function () {
						alert('登陆过期,请重新登录')
						window.location.href = "login.html";
						layer.msg("服务器繁忙")
					}
				});
				return false;
			}
		}
	})

	function PassViewById(row) {
		$('#myModal').modal();
		vm.qrCode.codeId = row.codeId
		vm.qrCode.liftId = row.liftId
		vm.qrCode.floor = row.floor
		vm.qrCode.liftAddress = row.liftAddress
		vm.qrCode.id = row.id
	}

	function RefuseViewById(row) {
		var obj = {
			"idList": [row.id]
		}
		var r = confirm("是否删除数据")
		if (r == false) {
			return;
		}
		$.ajax({
			type: "post",
			// url: 'https://ytcloud2.yungtay.com.cn:1443/proServer/access/passApplicatons',
			url: 'https://ytcloud2.yungtay.com.cn:1443/proServer/api/qrCode/delete',
			contentType: 'application/json;charset=utf-8',
			headers: {
				Token: my_token //这里是Token
			},
			data: JSON.stringify(obj),
			// data: {"status":1,"communityId":'1001'},
			traditional: true,
			success: function (res) {
				console.log(res)
				location.reload()
			},
			error: function (error) {
				alert('登陆过期,请重新登录')
				window.location.href = "login.html";
				alert(res.message)
				window.location.href = "login.html";
			}
		})
	}

	function refuseAll() {
		var r = confirm("是否删除数据")
		if (r == false) {
			return;
		}
		var row = $("#tb_application").bootstrapTable('getSelections');
		if (row.length == 0) { // rows 主要是为了判断是否选中，下面的else内容才是主要
			alert("请先选择要处理的记录!");
			return;
		}
		refuseIds = []

		for (var i = 0; i < row.length; i++) {
			refuseIds.push(row[i].id)
		}
		var obj = {
			"idList": refuseIds
		}
		$.ajax({
			type: "post",
			// url: 'https://ytcloud2.yungtay.com.cn:1443/proServer/access/passApplicatons',
			url: 'https://ytcloud2.yungtay.com.cn:1443/proServer/api/qrCode/delete',
			contentType: 'application/json;charset=utf-8',
			headers: {
				Token: my_token //这里是Token
			},
			data: JSON.stringify(obj),
			// data: {"status":1,"communityId":'1001'},
			traditional: true,
			success: function (res) {
				console.log(res)
				location.reload()
			},
			error: function (error) {
				alert('登陆过期,请重新登录')
				window.location.href = "login.html";
				console.log(error);
			}
		})
	}
	var TableInit = function () {
		var oTableInit = new Object();
		//获取token
		// 初始化Table
		oTableInit.Init = function () {
			$('#tb_application').bootstrapTable({
				ajax: function (request) { // 使用ajax请求
					$.ajax({
						type: "POST",
						url: 'https://ytcloud2.yungtay.com.cn:1443/proServer/api/qrCode/listOfPage',
						// url: 'http://10.21.30.26:9090/proServer/api/qrCode/listOfPage',
						contentType: 'application/json;charset=utf-8',
						dataType: 'json',
						data: JSON.stringify(request.data),
						success: function (res) {
							console.log(res.data)
							if (res.data) {
								request.success({
									row: res.data,
								});
							} else {
								alert(res.message)
								window.location.href = "login.html";

							}

							$('#tb_application').bootstrapTable('load', res.data);
						},
						error: function (error) {
							alert('登陆过期,请重新登录')
							window.location.href = "login.html";
							console.log(error);
						}
					})
				}, // 请求方式（*）
				toolbar: '#toolbar', // 工具按钮用哪个容器
				striped: true, // 是否显示行间隔色
				cache: false, // 是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
				pagination: true, // 是否显示分页（*）
				sortable: true, // 是否启用排序
				sortOrder: "asc", // 排序方式
				queryParams: oTableInit.queryParams, // 传递参数（*）
				sidePagination: "server", // 分页方式：client客户端分页，server服务端分页（*）
				pageNumber: 1, // 初始化加载第一页，默认第一页
				pageSize: 10, // 每页的记录行数（*）
				pageList: [10, 25, 50, 100], // 可供选择的每页的行数（*）
				search: false, // 是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
				strictSearch: false,
				showColumns: false, // 是否显示所有的列
				showRefresh: false, // 是否显示刷新按钮
				minimumCountColumns: 2, // 最少允许的列数
				clickToSelect: true, // 是否启用点击选中行
				height: '', // 行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
				uniqueId: "ID", // 每一行的唯一标识，一般为主键列
				showToggle: false, // 是否显示详细视图和列表视图的切换按钮
				cardView: false, // 是否显示详细视图
				detailView: false, // 是否显示父子表
				columns: [{
					checkbox: true
				}, {
					field: 'codeId',
					title: '二维码编号',
				}, {
					field: 'liftId',
					title: '电梯编码',
				}, {
					field: 'liftAddress',
					title: '电梯地址',
				}, {
					field: 'floor',
					title: '楼层',
				},  {
					field: 'makeCode',
					title: '二维码生成',
				}, {
					field: 'operate',
					title: '操作',
					width: '80px',
					formatter: operateFormatter
				}]
			});
		};

		function operateFormatter(value, row, index) {
			var id = index;
			var data = JSON.stringify(row);
			return [
				'<div class="btn-group">',
				"<button id='btnEditPicGroupDetail' type='button' class='btn btn-warning'  singleSelected=true  onclick='PassViewById(" +
				data + ")'>修改</button>",
				"<button id='btnUpMove' type='button' class='btn btn-danger' singleSelected=true onclick='RefuseViewById(" +
				data + ")'>删除</button>",
				'</div>'
			].join('');
		}

		function dateFormatter(value, row, index) {
			return formatDate(new Date(value))
		}
		// 得到查询的参数
		oTableInit.queryParams = function (params) {
			var temp = { // 这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
				searchParem: $("#txt_search_departmentname").val(),
				currentPage: parseInt(params.offset / params.limit) + 1,
				pageSize: params.limit, // 每頁個數
			};
			return temp;
		};
		return oTableInit;
	};
	var ButtonInit = function () {
		var oInit = new Object();
		var postdata = {};

		oInit.Init = function () {
			// 初始化页面上面的按钮事件
		};

		return oInit;
	};

	function getCookie(name) {
		var cookieValue = "啥也没有！！";
		if (document.cookie && document.cookie !== '') {
			var cookies = document.cookie.split(';');
			for (var i = 0; i < cookies.length; i++) {
				var cookie = $.trim(cookies[i]);
				if (cookie.substring(0, name.length + 1) === (name + '=')) {
					cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
</script>

</html>